<?php


namespace app\system\controller;

class System extends AdminBase
{
	public function get_async_server_run_status()
	{
		$root_path = \think\facade\Env::get("root_path");
		if (!is_file($root_path . "public/swoole_async_task_server.log")) {
			$this->response(\app\system\model\Code::error, "请先刷新状态");
		}
		$data = json_decode(file_get_contents($root_path . "public/swoole_async_task_server.log"));
		$this->response(\app\system\model\Code::success, "获取成功", $data);
	}
	public function refresh_async_server_run_status()
	{
		$client = open_swoole_client();
		if ($client) {
			$client->send(json_encode(["type" => "TestLog", "data" => []]));
			$client->close();
			$this->response(\app\system\model\Code::success, "已刷新");
		} else {
			$this->response(\app\system\model\Code::error, "刷新失败，连接swoole失败");
		}
	}
	public function reboot_async_server()
	{
		$client = open_swoole_client();
		if ($client) {
			$client->send(json_encode(["type" => "SwooleKill", "data" => []]));
			$client->close();
			$this->response(\app\system\model\Code::success, "已发送重启命令");
		} else {
			$this->response(\app\system\model\Code::error, "连接swoole失败");
		}
	}
	public function get_system_info($check_auth = false)
	{
		$root_path = \think\facade\Env::get("root_path");
		if (!is_file($root_path . "system/config/version.php")) {
			$this->response(\app\system\model\Code::error, "检测到系统配置文件缺失");
		}
		$system_version_config = (include $root_path . "system/config/version.php");
		$system = new \app\common\system\System();
		if ($check_auth) {
			$system->check_auth(false);
		}
		$system_product_config = $system->getProductInfo();
		$data = ["version" => $system_version_config, "product" => $system_product_config, "auths_info" => $system->getAuthInfo(), "product_key" => \app\common\server\ConfigServer::get("system_auth", "product_key", ""), "mysql_version_id" => \app\common\server\ConfigServer::get("system_auth", "mysql_version_id", "")];
		$this->response(\app\system\model\Code::success, "获取成功", $data);
	}
}